/*
 * TestDumpCCConstant.c
 *
 *  Created on: 2012/05/31
 *      Author: guanxiaoying
 */
#include "TestDump.h"

static VOID dumpConstant( AST astValue ){
	AST astType = CValueInfo.getType( astValue );

	sprintf( tempBuf, header_format, dumpGetStr(XML_RECORD), astValue );
	dumpOutputStream( tempBuf );

	sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_TYPE), "", astType );
	dumpOutputStream( tempBuf );
	sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_TYPE)  );
	dumpOutputStream( tempBuf );

	sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_VALUE), ""  );
	dumpOutputStream( tempBuf );
	dumpParameterStr(  dumpGetConstant ( astValue ) );

	sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_VALUE)  );
	dumpOutputStream( tempBuf );

	sprintf( tempBuf, tail_format,
			dumpGetStr(XML_RECORD) );
	dumpOutputStream( tempBuf );
}
PSZ  dumpGetConstant( AST astValue ){
	AST astType = CValueInfo.getType( astValue );
	if( CTypeInfo.isInteger( astType )){
		INTVALUE value = CValueInfo.getIntegerValue( astValue );
		sprintf( constantBuffer, "%s%llu", value.sign > 0?"":"-", value.u8Remainder );
	}else{
		DOUBLE value = CValueInfo.getFloatingValue( astValue );
		sprintf( constantBuffer, "%f", value );
	}
	return constantBuffer;
}
VOID DumpConstant( PSZ szPath, PSZ postfix ){
	AST astValue;
	AST astMax;

	if( szPath == NULL ){
		return;
	}
	strcpy( file_buf, szPath );
	file_buf[strlen(szPath)] = '\0';
	strcat(file_buf, postfix );
	file_buf[strlen(szPath)+strlen(postfix)] = '\0';
	if( COEXIT_SUCCESS == dumpOutputStreamInit_file(file_buf)){
		sprintf( tempBuf, top_header, dumpGetStr(XML_CONSTANT) );
		dumpOutputStream( tempBuf );
		astValue = MIN_ARRAY;
		astMax = CValueInfo.getMax();
		while( astValue <= astMax ){
			dumpConstant( astValue );
			astValue ++;
		}
		sprintf( tempBuf, top_end, dumpGetStr(XML_CONSTANT) );
		dumpOutputStream( tempBuf );
		dumpOutputStreamEnd_file();
	}
}


